package com.cn.goodsadmin.service;

import com.cn.goodsadmin.po.GoodsInfo;
import com.cn.goodsadmin.util.CipherUtil;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("GoodsInfoService")
public class GoodsInfoService extends BaseService{

    public void addGoods(GoodsInfo goodsInfo)throws Exception{
        String name=goodsInfo.getcGoodsname();
        String goodsid= CipherUtil.generatePassword(goodsInfo.getcAppid()+"_"+name);
        goodsInfo.setcGoodsid(goodsid);
        goodsInfoDao.save(goodsInfo);
    }

    public void updateGoods(GoodsInfo goodsInfo)throws Exception{
        goodsInfoDao.update(goodsInfo);
    }

    public List<GoodsInfo>  getAllGoodsInfo(int appid) throws Exception{
        List<GoodsInfo> goodsInfos=goodsInfoDao.findAllGoodsList(appid);
        return goodsInfos;
    }

    public void  delete(List<String> ids) throws Exception{
        for(String id:ids){
            GoodsInfo goodsInfo=goodsInfoDao.findGoodsInfoByid(id);
            goodsInfoDao.delete(goodsInfo);
        }
    }
}
